package cate.game.play.skill.passive.furniture;

import cate.common.table.d.GDAttr;
import cate.common.table.d.GDSkill;
import cate.game.attr.FightAttr;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.effect.SkillEffect;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 对最大生命值高于自身10%的目标造成额外5%-18%的伤害，
 * 对当前生命值低于自身5%的目标治疗加成提升8%-25%
 */
public class 生命抉择PH extends PassiveHandler {


	private double 伤害血量;
	private double 伤害下限;
	private double 伤害上限;

	private double 治疗血量;
	private double 治疗下限;
	private double 治疗上限;

	//伤害血量=1000&伤害下限=500&伤害上限=1800&
	//治疗血量=500&治疗下限=800&治疗上限=2500
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		伤害血量 = args.getWDouble("伤害血量", 0d);
		伤害下限 = args.getDouble("伤害下限", 0d);
		伤害上限 = args.getDouble("伤害上限", 0d);

		治疗血量 = args.getWDouble("治疗血量", 0d);
		治疗下限 = args.getDouble("治疗下限", 0d);
		治疗上限 = args.getDouble("治疗上限", 0d);
	}

	@Override
	public void afterSelectTargets(SkillActionCtx action, SkillEffect effect) {
		if (action.getSkill().cfg.isEffectType(GDSkill.EffectType.伤害)) {
			for (Fighter target : action.getTargets()) {
				if (target.attr.total().hpTotal() > skill.owner.attr.total().hpTotal() * (1 + 伤害血量)) {
					effect.getTargetCtx(target.getPid()).addHpCfgByCoeff(伤害下限 + Math.random() * (伤害上限 - 伤害下限));
				}
			}
			return;
		}
		if (action.getSkill().cfg.isEffectType(GDSkill.EffectType.治疗)) {
			for (Fighter target : action.getTargets()) {
				if (target.attr.total().hpCur() < skill.owner.attr.hpCur() * (1 - 治疗血量)) {
					effect.getTargetCtx(target.getPid()).addActorAttr(new FightAttr(GDAttr.HEAL_UP, 治疗下限 + Math.random() * (治疗下限 - 治疗上限)));
				}
			}
		}
	}
}
